<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="接收用户" prop="userName">
        <el-input v-model="form.userName" placeholder="请输入接收用户名" disabled/>
      </el-form-item>
      <el-form-item label="通知类型" prop="type">
        <el-select v-model="form.type" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="内容">
<!--        <editor v-model="form.content" :min-height="192"/>-->
        <div v-if="form.type==='公司'">
          <image-upload v-model="form.content"></image-upload>
<!--          <el-upload-->
<!--            action='/dev-api/common/upload'-->
<!--            list-type="picture-card"-->
<!--            :on-preview="handlePictureCardPreview"-->
<!--            :on-remove="handleRemove"-->
<!--            :on-success="success"-->
<!--            :headers="uploadHeaders"-->
<!--          >-->
<!--            <i class="el-icon-plus"></i>-->
<!--          </el-upload>-->
<!--          <el-dialog :visible.sync="dialogVisible">-->
<!--            < img width="100%" :src="dialogImageUrl"  alt="">-->
<!--          </el-dialog>-->
        </div>
        <el-input v-model="form.content" type="textarea":rows="13" placeholder="请输入内容" v-else  />
      </el-form-item>
      <el-form-item label="发布时间" prop="publishTime">
        <el-date-picker clearable
                        v-model="form.publishTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择发布时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注信息" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" style="margin-left: 550px">确 定</el-button>
      <el-button @click="cancel" style="margin-left: 20px">取 消</el-button>
    </div>
  </div>

</template>

<script>
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/scp/notice";
import {getToken} from "@/utils/auth";


export default {
  uploadHeaders: {
    Authorization: 'Bearer ' + getToken()
  },
  dialogImageUrl: '',
  dialogVisible: false,
  name: "edit",
  data(){
    return{
      form:{},
      rules:{
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择类型', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: 'blur' }
        ],
        publishTime: [
          { required: true, message: '请选择发布时间', trigger: 'blur' }
        ]
      },
      options: [{
        value: '系统',
        label: '系统'
      }, {
        value: '公司',
        label: '公司'
      }, {
        value: '新闻',
        label: '新闻'
      }]
    }
  },
  created() {
    var noticeId = this.$route.query.noticeId;
    this.init(noticeId)
  },
  methods:{
    success(res){
      this.form.content = res.msg
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    init(noticeId){
      getNotice(noticeId).then(response => {
        this.form = response.data;
        console.log(this.form)
        // if(this.form.type == '公司'){
        //   this.form.content = "http://127.0.0.1:9000/gh-scp/" + response.data.content
        // }
      });
    },
    submitForm() {

      updateNotice(this.form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.$router.back();
      });
    },
    cancel() {
      this.$router.back();
    }
  },
}
</script>

<style scoped>

</style>
